﻿package mortal.game.scene3D.display3d.blood.otherPlayerBlood
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import baseEngine.system.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.*;
    import frEngine.core.*;
    import frEngine.event.*;
    import frEngine.render.*;
    import frEngine.render.layer.*;
    import frEngine.shader.*;
    import frEngine.shader.registType.*;
    import mortal.game.scene3D.*;
    import mortal.game.scene3D.display3d.blood.*;
    import mortal.game.scene3D.layer3D.*;

    public class OPlayerBlood3DRender extends DefaultRender
    {
        public const list1Values:Vector.<Number>;
        private var _targetBloodSurface:FrSurface3D;
        private var _bloodMaterial:ShaderBase;
        private var _bloodPosListRegister:VcParam;
        private const depthCompare:String = "always";
        private const cullFace:String = "none";
        private const depthWrite:Boolean = false;
        private const sourceFactor:String = "one";
        private const destFactor:String = "oneMinusSourceAlpha";
        private static var _instance:OPlayerBlood3DRender;
        private static var _bloodMesh3d:Mesh3D;
        public static const maxNum:int = 100;

        public function OPlayerBlood3DRender()
        {
            this.list1Values = new Vector.<Number>;
            if (_instance && _instance != this)
            {
                return;
            }
            _instance = this;
            return;
        }// end function

        public function init(param1:GameScene3D) : void
        {
            if (!_bloodMesh3d)
            {
                _bloodMesh3d = new Mesh3D("bloods", false, LastRender.instance.renderList);
                _bloodMesh3d.setLayer(Layer3DManager.blood3DLayer, false);
                _bloodMesh3d.render = OPlayerBlood3DRender.instance;
                param1.addChild(_bloodMesh3d);
            }
            this._targetBloodSurface = Blood3DResource.instance.surface100_2;
            var _loc_2:* = new Point(132 / 256, 24 / 128);
            var _loc_3:* = new Point(0 / 256, 25 / 128);
            var _loc_4:* = new Point(0 / 256, 98 / 128);
            this._bloodMaterial = new ShaderBase("_bloodMaterial", new BloodVertexFilter(), new BloodFragmentFilter2(Blood3DResource.instance.blood3dTexture, _loc_2, _loc_3, _loc_4));
            FrEventDispatcher.instance.proxyAddEventListener(this._bloodMaterial, Engine3dEventName.MATERIAL_REBUILDER, this.reBuildHander);
            this._bloodMaterial.buildBytes();
            return;
        }// end function

        private function reBuildHander(event:Event) : void
        {
            this._bloodPosListRegister = this._bloodMaterial.getParam("{bloodPosList}", true);
            FrEventDispatcher.instance.proxyRemoveEventListener(this._bloodMaterial, Engine3dEventName.MATERIAL_REBUILDER, this.reBuildHander);
            return;
        }// end function

        override public function draw(param1:Mesh3D, param2:ShaderBase = null) : void
        {
            if (!this._bloodPosListRegister)
            {
                return;
            }
            if (!this._bloodMaterial.hasPrepared(param1, this._targetBloodSurface))
            {
                return;
            }
            if (this.list1Values.length > 0)
            {
                var _loc_3:* = Global3D;
                var _loc_4:* = Global3D.objectsDrawn + 1;
                _loc_3.objectsDrawn = _loc_4;
                this._bloodPosListRegister.value = this.list1Values;
                this._bloodMaterial.draw(param1, this._targetBloodSurface, this.depthCompare, this.cullFace, this.depthWrite, this.sourceFactor, this.destFactor, 0, this.list1Values.length * 0.5);
            }
            return;
        }// end function

        public static function get instance() : OPlayerBlood3DRender
        {
            if (!_instance)
            {
                _instance = new OPlayerBlood3DRender;
            }
            return _instance;
        }// end function

    }
}
